package com.yang.studentsapp.ui.life;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yang.studentsapp.Fish;
import com.yang.studentsapp.R;
import com.yang.studentsapp.RecycleViewDivider;
import com.yang.studentsapp.ui.adapter.BaseLoadMoreHeaderAdapter;
import com.yang.studentsapp.ui.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${Ян-Вэнь-Чао} on 2016/10/10.
 * 淘鱼
 */
public class FishFragment extends Fragment {
    RecyclerView recyclerfish;
    List<Fish> list = new ArrayList<>();

    FishAdapter adapter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_firsh, container, false);
        recyclerfish = (RecyclerView) view.findViewById(R.id.fish_recycler_view);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        for (int i = 0; i < 5; i++) {
            list.add(new Fish(R.mipmap.ic_launcher,"1564686584","1021天谴","120元",
                    R.mipmap.ic_launcher,"11111","经开区第五大街","11","121"));
        }

        adapter = new FishAdapter(getContext(), recyclerfish, list, R.layout.fish_recycler_item);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerfish.setLayoutManager(manager);
        recyclerfish.addItemDecoration(new RecycleViewDivider(getContext(),RecyclerView.HORIZONTAL,
                2,getResources().getColor(R.color.lightgray)));
        recyclerfish.setAdapter(adapter);

    }

    class FishAdapter extends BaseLoadMoreHeaderAdapter<Fish> {

        public FishAdapter(Context mContext, RecyclerView recyclerView, List<Fish> mDatas, int mLayoutId) {
            super(mContext, recyclerView, mDatas, mLayoutId);
        }

        @Override
        public void convert(Context mContext, RecyclerView.ViewHolder holder, Fish fish) {
            if (holder instanceof BaseViewHolder) {
                ((BaseViewHolder) holder).setText(R.id.fish_item_number, fish.getmNumber())
                        .setImageResource(R.id.fish_item_image, fish.getmIcon())
                        .setImageResource(R.id.fish_item_image1, fish.getmIcon1())
                        .setText(R.id.fish_item_address, fish.getmAddress())
                        .setText(R.id.fish_item_cost, fish.getmCost())
                        .setText(R.id.fish_item_time, fish.getmTime())
                        .setText(R.id.fish_item_edi_text, fish.getmEid())
                        .setText(R.id.fish_item_zan_number, fish.getmZan())
                        .setText(R.id.fish_item_mage_number, fish.getmMag());
            }
        }
    }
}
